package com.gxa.logistics.service.impl;

import com.gxa.logistics.domain.dto.TransferrecordDTO;
import com.gxa.logistics.domain.dto.WarehouseDTO;
import com.gxa.logistics.domain.vo.TransferrecordVO;
import com.gxa.logistics.domain.vo.WarehouseVO;
import com.gxa.logistics.mapper.TransferrecordMapper;
import com.gxa.logistics.mapper.WarehouseMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class TransferrecordServiceImpl {

    @Resource
    private TransferrecordMapper transferrecordMapper;


    public Map<String, Object> insert(TransferrecordDTO transferrecordDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增成功");
        transferrecordMapper.insert(transferrecordDTO);
        return map;
    }

    public Map<String, Object> delete(Integer transferrecord_id) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "删除成功");
        transferrecordMapper.delete(transferrecord_id);
        return map;
    }
    public Map<String, Object> update(TransferrecordDTO transferrecordDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "更新成功");
        transferrecordMapper.update(transferrecordDTO);
        return map;
    }

    public Map<String, Object> selectTransferrecordByMaterialName(String material_name) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "查询成功");
        TransferrecordDTO transferrecordDTO = transferrecordMapper.selectTransferrecordByMaterialName(material_name);
        map.put("data", transferrecordDTO);
        return map;
    }

    public Map<String, Object> selectTransferrecord(int page, int limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", transferrecordMapper.selectTransferrecordCount());    // 动态统计条数

        int index = (page - 1) * limit;
        map.put("data", transferrecordMapper.selectTransferrecord(index, limit));
        return map;
    }

}
